package com.cn.hjsj.appInterface.appImpl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.springframework.stereotype.Component;

import com.cn.hjsj.appInterface.appService.AppServiceTypeService;
import com.cn.hjsj.pojo.ServiceType;
import com.cn.hjsj.service.IServiceTypeService;
import com.cn.hjsj.util.log.LogUtil;

@Component("appServiceTypeImpl")
public class AppServiceTypeImpl implements AppServiceTypeService{
	@Resource(name = "serviceTypeService")
	private IServiceTypeService serviceTypeService;

	@Override
	public Map<String, Object> getServiceType(JSONObject object) {
		// TODO Auto-generated method stub
		Map<String, Object>  map=new HashMap<String,Object>(),
				mapOne=new HashMap<String,Object>(),
				maps=new HashMap<String,Object>(),
				mapTwo=new HashMap<String,Object>();
		JSONArray serviceType = new JSONArray();
		try{
			//获取 ServiceType 列表
			List<ServiceType> serviceTypeList = serviceTypeService.getList(maps);
			int count = serviceTypeService.getCount(maps);
			if(serviceTypeList!=null){
				for (int i=0;i<serviceTypeList.size();i++){
					mapOne.put("id", serviceTypeList.get(i).getId());
					mapOne.put("name", serviceTypeList.get(i).getName());				
					serviceType.add(mapOne);
				}
				
				LogUtil.info("/AppServiceTypeImpl/getServiceType:调用成功");
				mapTwo.put("serviceType", serviceType);
				mapTwo.put("count", count);
				map.put("code", "10000");
				map.put("data", mapTwo);
				map.put("mes", "调用成功");						
			}else{
				LogUtil.info("/AppServiceTypeImpl/getServiceType:调用成功");
				mapTwo.put("serviceType", serviceType);
				mapTwo.put("count", count);
				map.put("code", "10000");
				map.put("data", mapTwo);
				map.put("mes", "调用成功,数据库中无数据");
			}
			return map;
		}catch(Exception e){
			LogUtil.error("/AppServiceTypeImpl/getServiceType:解析参数异常！"+e.getMessage());
			map.put("code", "30000");
			map.put("mes", "参数列表初始化错误，可能不是合法的JSON数据格式！");
		
			return map;
		}
	}
}
